import React from 'react';
import {Icon as IconAntd} from 'antd';

import './index.scss';

//使用iconfont.cn来创建symbol引用的iconfont。
const IconCustom = IconAntd.createFromIconfontCN({scriptUrl: '//at.alicdn.com/t/font_1343068_7hc7dh4q28n.js'});

//自定义图标的类型
const types = ['shouye', 'wode', 'weixin', 'wodeguanzhu', 'xiaoxi', 'map_rectangle', 'map_polygon', 'map_finger'];

/**
 * 图标：包含antd的图标库和iconfont.cn中定义的图标
 * 参考：https://ant.design/components/icon-cn/
 */
export default class Icon extends React.Component {
  //自定义图标的类型
  static types = types;

  static defaultProps = {
    className: '',
    style: {}
  };

  render() {
    let {className, type, ...other} = this.props;

    let props = {className: `g-icon ${className}`, type, ...other};
    if (types.includes(type)) {
      return <IconCustom {...props} />;
    } else {
      return <IconAntd {...props} />;
    }
  }
}
